{extend name="main"}
{block name="style"}
<style type="text/css">
	.el-tree-node__content {
	    display: flex;
	    align-items: center;
	    height: 40px;
	    cursor: auto;
	}
	.custom-tree-node {
	    flex: 1;
	    display: flex;
	    align-items: center;
	    justify-content: space-between;
	    font-size: 14px;
	    padding-right: .5rem;
	}
	.w-40px{width: 40px;}
	.w-80px{width: 80px;}
	.w-180px{width: 180px;}
	.w-120px{width: 120px;}
	.w-240px{width: 240px;}
	.minw-200px{min-width: 200px;}
</style>
{/block}
{block name="body"}
<div class="bg-white p-3">
	<div class="pb-3">
        <el-button
            type="warning"
            size="mini"
            @click="updateFileAjax">
            更新缓存
        </el-button>
	</div>
	<div class="table-responsive">
		<el-table
		    :data="tableData"
		    style="width: 100%"
		    row-key="id"
    		stripe
		    lazy
		    :load="initHtml"
		    :tree-props="defaultProps">
		    <el-table-column
		      prop="id"
		      label="ID"
		      width="160">
		    </el-table-column>
		    <el-table-column
		      prop="pid"
		      label="上级ID"
		      width="100">
			      <template slot-scope="scope">
			      	{{scope.row.pid?scope.row.pid:''}}
			      </template>
		    </el-table-column>
		    <el-table-column
		      prop="title"
		      label="行业">
		    </el-table-column>
		    <el-table-column
		      prop="sort"
		      label="排序"
		      width="80">
		    </el-table-column>
		    <el-table-column
		      label="/"
		      width="80">
		      <template slot-scope="scope">
		        <el-button
		            type="primary"
		            size="minism"
		            @click="window.open('/jobs/editCate/'+scope.row.id)">
		            编辑
		        </el-button>
		      </template>
		    </el-table-column>
		</el-table>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			search:{
				cid:0,
			},
			tableData:[],
	        defaultProps: {
	          	label: 'title',
	          	children: 'children',
          		isLeaf: 'leaf'
	        }
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	updateFileAjax() {
		        this.$confirm('即将更新行业分类缓存, 是否继续?', '提示', {
		          confirmButtonText: '继续',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
		    		const loading=XYBase.openloading();
		    		$.getJSON('/industry/setCacheIndustry',function(ret) {
		    			loading.close();
		    			if(ret){
		    				if(ret.code === 0){
		    					XYBase.success(ret.msg);
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
		    		});
		        }).catch(() => {
					XYBase.msg('已取消');
		        });
	    	},
	      	initHtml(tree, treeNode, resolve) {
	      		var _this=this;
		      	if (typeof tree != "undefined")
		      		_this.search.cid=tree.id;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
						if (ret) {
							if (ret.code === 0) {
								if (!_this.search.cid) {
									_this.tableData=ret.data;
								}else{
									resolve(ret.data);
								}
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
	});
</script>
{/block}